X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=bindings%2Fpython-ctypes%2Fheader.py;h=cfe047b0e9375c5e2ff58402c02b1855ade12a18;hb=b9a85c736b72e21c32597840a0789cddbfdd88df;hp=4f4c870ade32bebe6f3215c1745387a7bffc5056;hpb=e23c4d69faf2003599f01b366fc64e1c006c34ea;p=vlc diff --git a/bindings/python-ctypes/header.py b/bindings/python-ctypes/header.py index 4f4c870ade..cfe047b0e9 100755 --- a/bindings/python-ctypes/header.py +++ b/bindings/python-ctypes/header.py @@ -33,6 +33,7 @@ create a libvlc Instance. From this instance, you can then create L{MediaPlayer} and L{MediaListPlayer} instances. """ +import logging import ctypes import sys @@ -91,19 +92,42 @@ class LibVLCException(Exception): pass # From libvlc_structures.h -class VLCException(ctypes.Structure): - """libvlc exception. - """ - _fields_= [ - ('raised', ctypes.c_int), - ('code', ctypes.c_int), - ('message', ctypes.c_char_p), - ] - def init(self): - libvlc_exception_init(self) - def clear(self): - libvlc_exception_clear(self) +# This is version-dependent, depending on the presence of libvlc_exception_get_message. + +if hasattr(dll, 'libvlc_exception_get_message'): + # New-style message passing + class VLCException(ctypes.Structure): + """libvlc exception. + """ + _fields_= [ + ('raised', ctypes.c_int), + ] + + @property + def message(self): + return dll.libvlc_exception_get_message() + + def init(self): + libvlc_exception_init(self) + + def clear(self): + libvlc_exception_clear(self) +else: + # Old-style exceptions + class VLCException(ctypes.Structure): + """libvlc exception. + """ + _fields_= [ + ('raised', ctypes.c_int), + ('code', ctypes.c_int), + ('message', ctypes.c_char_p), + ] + def init(self): + libvlc_exception_init(self) + + def clear(self): + libvlc_exception_clear(self) class PlaylistItem(ctypes.Structure): _fields_= [ @@ -201,10 +225,13 @@ def check_vlc_exception(result, func, args): """Error checking method for functions using an exception in/out parameter. """ ex=args[-1] + if not isinstance(ex, (VLCException, MediaControlException)): + logging.warn("python-vlc: error when processing function %s. Please report this as a bug to vlc-devel@videolan.org" % str(func)) + return result # Take into account both VLCException and MediacontrolException: c=getattr(ex, 'raised', getattr(ex, 'code', 0)) if c: - raise LibVLCException(args[-1].message) + raise LibVLCException(ex.message) return result ### End of header.py ###