]> git.sesse.net Git - vlc/commitdiff
python-ctypes: convert NULL return values to None
authorOlivier Aubert <olivier.aubert@liris.cnrs.fr>
Fri, 31 Jul 2009 12:40:58 +0000 (14:40 +0200)
committerOlivier Aubert <olivier.aubert@liris.cnrs.fr>
Fri, 31 Jul 2009 12:40:58 +0000 (14:40 +0200)
bindings/python-ctypes/generate.py

index 473980c0d27cbe960a6da34da07963dcb4e2fe4c..d44142ffb2b5d3fe7dca62192ca5f57525f622db 100755 (executable)
@@ -470,12 +470,17 @@ def generate_wrappers(methods):
     for classname, el in itertools.groupby(elements, key=operator.itemgetter(0)):
         print """
 class %(name)s(object):
     for classname, el in itertools.groupby(elements, key=operator.itemgetter(0)):
         print """
 class %(name)s(object):
-    def __init__(self, pointer=None):
+    def __new__(cls, pointer=None):
         '''Internal method used for instanciating wrappers from ctypes.
         '''
         if pointer is None:
             raise Exception("Internal method. You should instanciate objects through other class methods (probably named 'new' or ending with 'new')")
         '''Internal method used for instanciating wrappers from ctypes.
         '''
         if pointer is None:
             raise Exception("Internal method. You should instanciate objects through other class methods (probably named 'new' or ending with 'new')")
-        self._as_parameter_=ctypes.c_void_p(pointer)
+        if pointer == 0:
+            return None
+        else:
+            o=object.__new__(cls)
+            o._as_parameter_=ctypes.c_void_p(pointer)
+            return o
 
     @staticmethod
     def from_param(arg):
 
     @staticmethod
     def from_param(arg):