[vlc-commits] Check that function is present before registering its ctype wrapper in the module globals

Jean Brouwers git at videolan.org
Tue Jan 17 12:25:33 CET 2012


vlc/python | branch: master | Jean Brouwers <MrJean1 at Gmail.com> | Tue Jan 17 12:24:21 2012 +0100| [383aeb0ab640481e71f18e5bddea88365d2e4583] | committer: Olivier Aubert

Check that function is present before registering its ctype wrapper in the module globals

Signed-off-by: Olivier Aubert <olivier.aubert at liris.cnrs.fr>

> http://git.videolan.org/gitweb.cgi/vlc/python.git/?a=commit;h=383aeb0ab640481e71f18e5bddea88365d2e4583
---

 header.py |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/header.py b/header.py
index 4e12efb..af48c87 100755
--- a/header.py
+++ b/header.py
@@ -126,6 +126,7 @@ try:
     _Ints = (int, long)
 except NameError:  # no long in Python 3+
     _Ints =  int
+_Seqs = (list, tuple)
 
 # Default instance. It is used to instanciate classes directly in the
 # OO-wrapper.
@@ -139,19 +140,24 @@ def get_default_instance():
         _default_instance = Instance()
     return _default_instance
 
-_Seqs = (list, tuple)
-
 _Cfunctions = {}  # from LibVLC __version__
+_Globals = globals()  # sys.modules[__name__].__dict__
 
 def _Cfunction(name, flags, errcheck, *types):
     """(INTERNAL) New ctypes function binding.
     """
-    if hasattr(dll, name):
+    if hasattr(dll, name) and name in _Globals:
         p = ctypes.CFUNCTYPE(*types)
         f = p((name, dll), flags)
         if errcheck is not None:
             f.errcheck = errcheck
-        _Cfunctions[name] = f
+        # replace the Python function
+        # in this module, but only when
+        # running as python -O or -OO
+        if __debug__:
+            _Cfunctions[name] = f
+        else:
+            _Globals[name] = f
         return f
     raise NameError('no function %r' % (name,))
 



More information about the vlc-commits mailing list