[pygobject] Proper handling of null-ok in virtual methods
- From: Tomeu Vizoso <tomeuv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Proper handling of null-ok in virtual methods
- Date: Mon, 21 Jun 2010 15:51:40 +0000 (UTC)
commit 79acac7b86ec52cd3681d94d7f116314c3f00167
Author: Ludovic L'Hours <ludovic lhours gmail com>
Date: Tue Jul 21 16:28:34 2009 +0200
Proper handling of null-ok in virtual methods
https://bugzilla.gnome.org/show_bug.cgi?id=589253
codegen/codegen.py | 2 ++
codegen/reversewrapper.py | 18 +++++++++++++++---
2 files changed, 17 insertions(+), 3 deletions(-)
---
diff --git a/codegen/codegen.py b/codegen/codegen.py
index 73324a5..008f01c 100755
--- a/codegen/codegen.py
+++ b/codegen/codegen.py
@@ -615,6 +615,7 @@ class Wrapper:
handler, props = argtypes.matcher.get_reverse(
param.ptype)
props["direction"] = param.pdir
+ props["nullok"] = param.pnull
wrapper.add_parameter(handler(wrapper,
param.pname, **props))
buf = reversewrapper.MemoryCodeSink()
@@ -1168,6 +1169,7 @@ class GInterfaceWrapper(GObjectWrapper):
handler, props = argtypes.matcher.get_reverse(
param.ptype)
props["direction"] = param.pdir
+ props["nullok"] = param.pnull
wrapper.add_parameter(
handler(wrapper, param.pname, **props))
buf = reversewrapper.MemoryCodeSink()
diff --git a/codegen/reversewrapper.py b/codegen/reversewrapper.py
index ed48629..b96e12e 100644
--- a/codegen/reversewrapper.py
+++ b/codegen/reversewrapper.py
@@ -408,10 +408,22 @@ class StringParam(Parameter):
% (self.name, self.name, self.name)),
cleanup=("Py_XDECREF(py_%s);" % self.name))
self.wrapper.add_pyargv_item("py_%s" % self.name, optional=True)
- else:
+ elif self.props.get('nullok', False):
self.wrapper.add_declaration("PyObject *py_%s;" % self.name)
- self.wrapper.write_code(code=("py_%s = PyString_FromString(%s);" %
- (self.name, self.name)),
+ self.wrapper.write_code(code=("if (%s)\n"
+ " py_%s = PyString_FromString(%s);\n"
+ "else {\n"
+ " Py_INCREF(Py_None);\n"
+ " py_%s = Py_None;\n"
+ "}\n"
+ % (self.name, self.name, self.name, self.name)),
+ cleanup=("Py_DECREF(py_%s);" % self.name))
+ self.wrapper.add_pyargv_item("py_%s" % self.name)
+ else:
+ self.wrapper.add_declaration("PyObject *py_%s = NULL;" % self.name)
+ self.wrapper.write_code(code=("if (%s)\n"
+ " py_%s = PyString_FromString(%s);\n" %
+ (self.name, self.name, self.name)),
cleanup=("Py_DECREF(py_%s);" % self.name),
failure_expression=("!py_%s" % self.name))
self.wrapper.add_pyargv_item("py_%s" % self.name)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]