[vlc-devel] commit: python-ctypes: convert NULL return values to None (Olivier Aubert )
git version control
git at videolan.org
Fri Jul 31 15:00:45 CEST 2009
vlc | branch: master | Olivier Aubert <olivier.aubert at liris.cnrs.fr> | Fri Jul 31 14:40:58 2009 +0200| [e9210428005b1cb4baaf3130ba13d5bf4a4445e6] | committer: Olivier Aubert
python-ctypes: convert NULL return values to None
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e9210428005b1cb4baaf3130ba13d5bf4a4445e6
---
bindings/python-ctypes/generate.py | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/bindings/python-ctypes/generate.py b/bindings/python-ctypes/generate.py
index 473980c..d44142f 100755
--- a/bindings/python-ctypes/generate.py
+++ b/bindings/python-ctypes/generate.py
@@ -470,12 +470,17 @@ def generate_wrappers(methods):
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')")
- 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):
More information about the vlc-devel
mailing list