summaryrefslogtreecommitdiffstats
path: root/bindings
diff options
context:
space:
mode:
authorFrederic Peters <fpeters@entrouvert.com>2008-04-29 12:01:50 +0000
committerFrederic Peters <fpeters@entrouvert.com>2008-04-29 12:01:50 +0000
commit26bbd4a6e3f9a921f13ba6a73b4bf174c3809fba (patch)
tree009c4203ca432d6b3ac8fcc8bbc63253872d5cc2 /bindings
parente7e6b7170c3102d0208bf8cbbe99601d5a6d8162 (diff)
downloadlasso-26bbd4a6e3f9a921f13ba6a73b4bf174c3809fba.tar.gz
lasso-26bbd4a6e3f9a921f13ba6a73b4bf174c3809fba.tar.xz
lasso-26bbd4a6e3f9a921f13ba6a73b4bf174c3809fba.zip
[project @ fpeters@0d.be-20071005162859-0pf7l8zkie7m9sr5]
generate wrapper for get accessors import lasso s = lasso.Samlp2AuthnRequest() print s.isPassive Original author: Frederic Peters <fpeters@0d.be> Date: 2007-10-05 18:28:59.741000+02:00
Diffstat (limited to 'bindings')
-rw-r--r--bindings/lang_python.py53
-rw-r--r--bindings/t.py7
2 files changed, 60 insertions, 0 deletions
diff --git a/bindings/lang_python.py b/bindings/lang_python.py
index 420395c1..ce3fb288 100644
--- a/bindings/lang_python.py
+++ b/bindings/lang_python.py
@@ -162,11 +162,64 @@ _lasso.init()
for m in self.binding_data.functions:
self.generate_function_wrapper(m, fd)
for c in self.binding_data.structs:
+ self.generate_member_wrapper(c, fd)
for m in c.methods:
self.generate_function_wrapper(m, fd)
self.generate_wrapper_list(fd)
print >> fd, open('lang_python_wrapper_bottom.c').read()
+ def generate_member_wrapper(self, c, fd):
+ klassname = c.name
+ for m in c.members:
+ mname = format_as_python(m[1])
+ print >> fd, '''static PyObject*
+%s_%s_get(PyObject *self, PyObject *args)
+{''' % (klassname[5:], mname)
+ self.wrapper_list.append('%s_%s_get' % (klassname[5:], mname))
+
+ print >> fd, ' %s return_value;' % m[0]
+ print >> fd, ' PyObject* return_pyvalue;'
+ print >> fd, ' PyGObjectPtr* cvt_this;'
+ print >> fd, ' %s* this;' % klassname
+
+ print >> fd, ' if (! PyArg_ParseTuple(args, "O", &cvt_this)) return NULL;'
+ print >> fd, ' this = (%s*)cvt_this->obj;' % klassname
+
+ print >> fd, ' return_value = this->%s;' % m[1];
+
+ if m[0] == 'gboolean':
+ print >> fd, ' if (return_value) {'
+ print >> fd, ' Py_INCREF(Py_True);'
+ print >> fd, ' return Py_True;'
+ print >> fd, ' } else {'
+ print >> fd, ' Py_INCREF(Py_False);'
+ print >> fd, ' return Py_False;'
+ print >> fd, ' }'
+ elif m[0] in ('int', 'gint'):
+ print >> fd, ' return_pyvalue = PyInt_FromLong(return_value);'
+ print >> fd, ' Py_INCREF(return_pyvalue);'
+ print >> fd, ' return return_pyvalue;'
+ elif m[0] in ('char*', 'gchar*'):
+ print >> fd, ' if (return_value) {'
+ print >> fd, ' return_pyvalue = PyString_FromString(return_value);'
+ print >> fd, ' Py_INCREF(return_pyvalue);'
+ print >> fd, ' return return_pyvalue;'
+ print >> fd, ' } else {'
+ print >> fd, ' Py_INCREF(Py_None);'
+ print >> fd, ' return Py_None;'
+ print >> fd, ' }'
+ else:
+ print >> fd, ' if (return_value) {'
+ print >> fd, ' return_pyvalue = PyGObjectPtr_New(G_OBJECT(return_value));'
+ print >> fd, ' Py_INCREF(return_pyvalue);'
+ print >> fd, ' return return_pyvalue;'
+ print >> fd, ' } else {'
+ print >> fd, ' Py_INCREF(Py_None);'
+ print >> fd, ' return Py_None;'
+ print >> fd, ' }'
+
+ print >> fd, '}'
+ print >> fd, ''
def generate_function_wrapper(self, m, fd):
name = m.name[6:]
diff --git a/bindings/t.py b/bindings/t.py
index af791b65..0db85b56 100644
--- a/bindings/t.py
+++ b/bindings/t.py
@@ -98,6 +98,7 @@ def parse_header(header_file):
in_enum = False
in_struct = None
in_struct_private = False
+ in_ifdef_zero = False
lines = file(header_file).readlines()
i = 0
@@ -112,6 +113,12 @@ def parse_header(header_file):
in_comment = False
elif '/*' in line and not '*/' in line:
in_comment = True
+ elif in_ifdef_zero:
+ # minimal support for code sections commented with #if 0
+ if line.startswith('#endif'):
+ in_ifdef_zero = False
+ elif line.startswith('#if 0'):
+ in_ifdef_zero = True
elif in_enum:
if line.startswith('}'):
in_enum = False